## general project attr 
project (GRAPE C)
cmake_minimum_required(VERSION 3.5)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(MY_CMAKE_PATH ${CMAKE_SOURCE_DIR}/cmake)

# set build type according to dir name
IF(CMAKE_BINARY_DIR MATCHES "debug"  )
        set(CMAKE_BUILD_TYPE "Debug")
else()
        set(CMAKE_BUILD_TYPE "Release")
endif()
message("CMAKE_BUILD_TYPE -> ${CMAKE_BUILD_TYPE}")
message("CMAKE_SOURCE_DIR -> ${CMAKE_SOURCE_DIR}")
message("CMAKE_BINARY_DIR -> ${CMAKE_BINARY_DIR}")

## find and link part 
# metics 
include(${MY_CMAKE_PATH}/FindMETIS.cmake)
# igraph 
include(${MY_CMAKE_PATH}/FindIGRAPH.cmake)
# zlog
include(${MY_CMAKE_PATH}/FindZLOG.cmake)
# pthread
find_package(Threads)

# jni
find_package(JNI REQUIRED)
if(JNI_FOUND)
        message("JNI_INCLUDE_DIRS -> ${JNI_INCLUDE_DIRS}")
        MESSAGE("JNI_LIBRARIES -> ${JNI_LIBRARIES}")
        MESSAGE("JAVA_INCLUDE_PATH -> ${JAVA_INCLUDE_PATH}")
ENDIF()

#############################################################
set(ALL_DEPEND_INCLUDE 
        ${JNI_INCLUDE_DIRS}
        ${JAVA_INCLUDE_PATH2}
        ${JAVA_INCLUDE_PATH}
        ${METIS_INCLUDE} 
        ${IGRAPH_INCLUDE} 
        ${ZLOG_INCLUD}
        ${CMAKE_SOURCE_DIR}/include
        ${GKLIB_INCLUDE}
        ${IGRAPH_INTERNAL_INCLUDE})
include_directories(${ALL_DEPEND_INCLUDE})
#############################################################

## target definition 
file(GLOB GRAPE_CORE_SRC ${CMAKE_SOURCE_DIR}/core/*.c)
add_library(grape SHARED ${GRAPE_CORE_SRC})
set(ALL_DEPEND_LIB ${METIS_LIB} ${IGRAPH_LIB} ${ZLOG_LIB} m ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(grape ${ALL_DEPEND_LIB})
list(APPEND ALL_DEPEND_LIB grape)

add_subdirectory(sssp)
add_subdirectory(prog)
add_subdirectory(test)

# install

install(TARGETS grape 
        LIBRARY DESTINATION lib/
        )

install(DIRECTORY include
        DESTINATION include/GRAPE
        )

install(FILES zlog.conf 
        DESTINATION bin/
        )




